package com.gitee.freakchicken.dbapi.basic.controller;

import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.fastjson.JSONObject;
import com.gitee.freakchicken.dbapi.basic.dao.C_2GVtrLEN;
import com.gitee.freakchicken.dbapi.basic.domain.DataSource;
import com.gitee.freakchicken.dbapi.basic.util.C_LS6YRMwy;
import com.gitee.freakchicken.dbapi.basic.util.C_66X3zUSZ;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/table")
public class C_uoO4YkLP {

    @Autowired
    C_2GVtrLEN gf_Nb7IlXPC;

    @RequestMapping("/getAllTables")
    public List<JSONObject> m_mBWRpJxu(String sourceId) throws SQLException {
        DataSource lf_iJbyog1i = gf_Nb7IlXPC.selectById(sourceId);
        DruidPooledConnection lf_mJcX4fh9 = C_66X3zUSZ.m_SWdS8zKL(lf_iJbyog1i);
        List<String> lf_0a5KgYiE = C_LS6YRMwy.m_0Zp1iJaY(lf_mJcX4fh9, lf_iJbyog1i.getJdbcDataSource().getTableSql());
        List<JSONObject> lf_N1cphV7y = lf_0a5KgYiE.stream().map(lambda_lf_scjXOMSi -> {
            JSONObject lf_5rYl2Hgr = new JSONObject();
            lf_5rYl2Hgr.put("label", lambda_lf_scjXOMSi);
            try {
                DruidPooledConnection lf_kYkO0Nod = C_66X3zUSZ.m_SWdS8zKL(lf_iJbyog1i);
                lf_5rYl2Hgr.put("columns", C_LS6YRMwy.m_xrCMPx2Y(lf_kYkO0Nod, lf_iJbyog1i.getType(), lambda_lf_scjXOMSi));
            } catch (SQLException e) {
                e.printStackTrace();
            }
            lf_5rYl2Hgr.put("showColumns", false);
            return lf_5rYl2Hgr;
        }).collect(Collectors.toList());
        return lf_N1cphV7y;
    }

    @RequestMapping("/getAllColumns")
    public List<JSONObject> m_mBWRpJxu(String sourceId, String table) throws SQLException {
        DataSource lf_c2uOCKQb = gf_Nb7IlXPC.selectById(sourceId);
        DruidPooledConnection lf_LJKVHfk1 = C_66X3zUSZ.m_SWdS8zKL(lf_c2uOCKQb);
        List<JSONObject> lf_wAl7RUhP = C_LS6YRMwy.m_xrCMPx2Y(lf_LJKVHfk1, lf_c2uOCKQb.getType(), table);
        return lf_wAl7RUhP;
    }
}
